﻿using Core;
using Core.Data;
using Core.Domain;
using Core.Domain.Catalog;
using Core.Domain.Common;
using Core.Domain.Companys;
using Core.Domain.Customers;
using Core.Domain.Directory;
using Core.Domain.Localization;
using Core.Domain.Security;
using Core.Domain.Seo;
using Core.Domain.Stores;
using Core.Domain.Topics;
using Core.Infrastructure;
using Services.Configuration;
using Services.ExtendedAttributes;
using Services.Localization;
using Services.Security;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Services.Installation
{
    /// <summary>
    /// 增加数据字典项
    /// </summary>
    public partial class CodeFirstInstallationService : IInstallationService
    {
        #region Fields

        private readonly IRepository<Store> _storeRepository;
        private readonly IRepository<Customer> _customerRepository;
        private readonly IRepository<CustomerRole> _customerRoleRepository;
        private readonly IRepository<Topic> _topicRepository;
        private readonly IRepository<Category> _categoryRepository;
        private readonly IRepository<UrlRecord> _urlRecordRepository;
        private readonly IRepository<FriendlyLink> _friendlyLinkRepository;
        private readonly IRepository<Scale> _scaleRepository;
        private readonly IRepository<Company> _companyRepository;
        private readonly IRepository<Jobs> _jobRepository;
        private readonly IRepository<LocaleStringResource> _localStringRepository;
        private readonly IRepository<City> _cityRepository;
        private readonly IRepository<StateProvince> _stateRepository;
        private readonly IRepository<ExtendedAttribute> _extendRepository;
        private readonly IRepository<ExtendedAttributeValue> _extendValueRepository;
        private readonly IRepository<Resume> _resumeRepository;
        private readonly IRepository<WorkExperience> _workRepository;
        private readonly IRepository<Education> _educationRepository;
        private readonly IWebHelper _webHelper;

        #endregion

        #region Ctor

        public CodeFirstInstallationService(
            IRepository<Store> storeRepository,
            IRepository<Customer> customerRepository,
            IRepository<CustomerRole> customerRoleRepository,
            IRepository<Topic> topicRepository,
            IRepository<Category> categoryRepository,
            IRepository<UrlRecord> urlRecordRepository,
            IRepository<FriendlyLink> friendlyLinkRepository,
            IRepository<Scale> scaleRepository,
            IRepository<Company> companyRepository,
            IRepository<LocaleStringResource> localStringRepository,
            IRepository<Jobs> jobRepository,
            IRepository<City> cityRepository,
            IRepository<StateProvince> stateRepository,
            IRepository<ExtendedAttribute> extendRepository,
            IRepository<ExtendedAttributeValue> extendValueRepository,
            IRepository<Resume> resumeRepository,
            IRepository<WorkExperience> workRepository,
            IRepository<Education> educationRepository,
            IWebHelper webHelper
            )
        {
            this._storeRepository = storeRepository;
            this._customerRepository = customerRepository;
            this._customerRoleRepository = customerRoleRepository;
            this._topicRepository = topicRepository;
            this._categoryRepository = categoryRepository;
            this._urlRecordRepository = urlRecordRepository;
            this._friendlyLinkRepository = friendlyLinkRepository;
            this._scaleRepository = scaleRepository;
            this._companyRepository = companyRepository;
            this._jobRepository = jobRepository;
            this._webHelper = webHelper;
            this._localStringRepository = localStringRepository;
            this._cityRepository = cityRepository;
            this._stateRepository = stateRepository;
            this._extendRepository = extendRepository;
            this._extendValueRepository = extendValueRepository;
            this._resumeRepository = resumeRepository;
            this._workRepository = workRepository;
            this._educationRepository = educationRepository;
        }

        #endregion

        #region Utilities

        /// <summary>
        /// 安装默认站点
        /// </summary>
        protected virtual void InstallStores()
        {
            var stores = new List<Store>()
            {
                new Store()
                {
                    Name = "站点名称",
                    Url = "http://***",
                    SslEnabled = false,
                    Hosts = "yourstore.com,www.yourstore.com",
                    DisplayOrder = 1,
                },
            };

            stores.ForEach(x => _storeRepository.Insert(x));
        }

        /// <summary>
        /// 安装基本用户
        /// </summary>
        /// <param name="defaultUserEmail"></param>
        /// <param name="defaultUserPassword"></param>
        protected virtual void InstallCustomersAndUsers(string defaultUserEmail, string defaultUserPassword)
        {
            var customerRole = new List<CustomerRole>() { 
                new CustomerRole(){
                    SysRole = SystemRole.Registered,
                    Name="注册用户",
                    Active = true,
                },
                new CustomerRole(){
                    SysRole = SystemRole.Guests,
                    Name="匿名用户",
                    Active = true,
                },
                new CustomerRole(){
                    SysRole = SystemRole.Administrators,
                    Name="系统用户",
                    Active = true,
                },
            };

            customerRole.ForEach(e => _customerRoleRepository.Insert(e));


            var encryptionService = EngineContext.Current.Resolve<IEncryptionService>();
            var salt = "";
            var customers = new List<Customer>()
            {                
                new Customer()
                {                    
                    CustomerGuid = Guid.NewGuid(),
                    Email = defaultUserEmail,
                    Username = defaultUserEmail,           
                    Active = true,
                    CreatedOn = DateTime.UtcNow,
                    Deleted =false,
                    IsSystemAccount =false,
                    PasswordSalt = salt= encryptionService.CreateSaltKey(5),
                    Password = encryptionService.CreatePasswordHash(defaultUserPassword, salt, ""),
                    Phone="13800000000",    
                    RegisterEnum= RegisterEnum.Other,
                    CustomerRole =_customerRoleRepository.Table.FirstOrDefault(e=>e.SysRole == SystemRole.Administrators),
                },
                 new Customer()
                {
                    CustomerGuid = Guid.NewGuid(),
                    Email = defaultUserEmail,
                    Username = "aaa@admin.com",
                    Password = "admin",
                    Active = true,
                    CreatedOn = DateTime.UtcNow,
                    Deleted =false,
                    IsSystemAccount =false,
                    Phone="13800000000",    
                    RegisterEnum= RegisterEnum.Applicant,
                    CustomerRole =_customerRoleRepository.Table.FirstOrDefault(e=>e.SysRole == SystemRole.Registered),

                },
                 new Customer()
                {
                    CustomerGuid = Guid.NewGuid(),
                    Email = defaultUserEmail,
                    Username = "bbb@admin.com",
                    Password = "admin",
                    Active = true,
                    CreatedOn = DateTime.UtcNow,
                    Deleted =false,
                    IsSystemAccount =false,
                    Phone="13800000000",    
                    RegisterEnum= RegisterEnum.Company,
                    CustomerRole =_customerRoleRepository.Table.FirstOrDefault(e=>e.SysRole == SystemRole.Registered),
                },
                
                 new Customer()
                {
                    CustomerGuid = Guid.NewGuid(),
                    Email = defaultUserEmail,
                    Username = "ccc@admin.com",
                    Password = "admin",
                    Active = true,
                    CreatedOn = DateTime.UtcNow,
                    Deleted =false,
                    IsSystemAccount =false,
                    Phone="13800000000",    
                    RegisterEnum= RegisterEnum.HeadHunter,
                    CustomerRole =_customerRoleRepository.Table.FirstOrDefault(e=>e.SysRole == SystemRole.Registered),
                },
                 new Customer()
                {
                    CustomerGuid = Guid.NewGuid(),
                    Email = defaultUserEmail,
                    Username = "bbb@admin.com",
                    Password = "admin",
                    Active = true,
                    CreatedOn = DateTime.UtcNow,
                    Deleted =false,
                    IsSystemAccount =false,
                    Phone="13800000000",    
                    RegisterEnum= RegisterEnum.HeadHunter,
                    CustomerRole =_customerRoleRepository.Table.FirstOrDefault(e=>e.SysRole == SystemRole.Guests),
                },
            };

            customers.ForEach(x => _customerRepository.Insert(x));
        }

        /// <summary>
        /// 安装配置信息
        /// </summary>
        protected virtual void InstallSettings()
        {
            var settingService = EngineContext.Current.Resolve<ISettingService>();

            settingService.SaveSetting(new CustomerSettings()
            {
                NameMethod = RegisterMethod.Name,
                PasswordMinLength = 6,
                AvatarMaximumSizeBytes = 20000,
                DefaultAvatarEnabled = true,
                ShowCustomersJoinDate = false,
                AcceptPrivacyPolicyEnabled = false,
                OnlineCustomerMinutes = 20,
                StoreLastVisitedPage = false,
                SuffixDeletedCustomers = false,
            });


            settingService.SaveSetting(new SeoSettings()
            {
                PageTitleSeparator = " - ",
                PageTitleSeoAdjustment = PageTitleSeoAdjustment.PagenameAfterStorename,
                DefaultTitle = "Your store",
                DefaultMetaKeywords = "",
                DefaultMetaDescription = "",
                WwwRequirement = WwwRequirement.NoMatter,
            });

            settingService.SaveSetting(new CommonSettings()
            {
                SitemapEnabled = true,
                DisplayJavaScriptDisabledWarning = false,
                UseFullTextSearch = false,
                FullTextMode = FulltextSearchMode.ExactMatch,
                Log404Errors = true,
                RenderXuaCompatible = false,
                XuaCompatibleValue = "IE=edge",
                PageSize = 20,
                PageSizeOptions = "20,10,30",
                RedisPort = 6379,
                AllowCustomersToSelectPageSize = false,
            });

            settingService.SaveSetting(new SeoSettings()
            {
                PageTitleSeparator = ". ",
                PageTitleSeoAdjustment = PageTitleSeoAdjustment.PagenameAfterStorename,
                DefaultTitle = "Your store",
                DefaultMetaKeywords = "",
                DefaultMetaDescription = "",
                WwwRequirement = WwwRequirement.NoMatter,
            });

            settingService.SaveSetting(new LocalizationSettings()
            {
                LoadAllLocaleRecordsOnStartup = true,
                LoadAllLocalizedPropertiesOnStartup = true,
                LoadAllUrlRecordsOnStartup = false,
            });

            settingService.SaveSetting(new SecuritySettings()
            {
                EncryptionKey = CommonHelper.GenerateRandomDigitCode(16),
            });
        }

        /// <summary>
        /// 安装资源信息
        /// </summary>
        protected virtual void InstallLocaleResources()
        {
            //保存资源
            foreach (var filePath in System.IO.Directory.EnumerateFiles(_webHelper.MapPath("~/App_Data/Localization/"), "*.nopres.xml", SearchOption.TopDirectoryOnly))
            {
                var localesXml = File.ReadAllText(filePath);
                var localizationService = EngineContext.Current.Resolve<ILocalizationService>();
                //localizationService.ImportResourcesFromXml(localesXml);
            }

        }

        /// <summary>
        /// 增加主题
        /// </summary>
        protected virtual void InstallTopics()
        {
            var topics = new List<Topic>
            {
                new Topic{
                        SystemName = "AboutUs",
                        IncludeInSitemap = true,
                        Title="关于我们",
                        Body = "<p>这是关于我们的内容信息.</p>"},
                new Topic{
                        SystemName="Register",
                        IncludeInSitemap = true,
                        Title = "加入我们",
                        Body="<p>这是加入我们的内容</p>"}
            };
            topics.ForEach(t => _topicRepository.Insert(t));
        }

        /// <summary>
        /// 新增类别
        /// </summary>
        protected virtual void InstallCategories()
        {


            //categories
            var allCategories = new List<Category>();
            var categoryBooks = new Category
            {
                Name = "技术",
                DisplayOrder = 1,
                CreatedOn = DateTime.UtcNow,
                Active = true,
                Deleted = false,
                ParentId = 0,
                SeName = "jishu",
            };


            allCategories.Add(categoryBooks);
            _categoryRepository.Insert(categoryBooks);

            var categoryComputers = new Category
            {
                Name = "产品",
                DisplayOrder = 2,
                CreatedOn = DateTime.UtcNow,
                Active = true,
                Deleted = false,
                ParentId = 0,
                SeName = "chanpin",
            };
            allCategories.Add(categoryComputers);
            _categoryRepository.Insert(categoryComputers);


            var categoryDesktops = new Category
            {
                Name = "销售",
                DisplayOrder = 3,
                CreatedOn = DateTime.UtcNow,
                Active = true,
                Deleted = false,
                ParentId = 0,
                SeName = "xiaoshou",
            };
            allCategories.Add(categoryDesktops);
            _categoryRepository.Insert(categoryDesktops);


            //search engine names
            foreach (var category in allCategories)
            {
                _urlRecordRepository.Insert(new UrlRecord()
                {
                    EntityId = category.Id,
                    EntityName = "Category",
                    IsActive = true,
                    Slug = category.SeName
                });
            }
        }

        /// <summary>
        /// 增加友情链接
        /// </summary>
        protected virtual void InstallFriendlyLinks()
        {
            var links = new List<FriendlyLink>()
            {
                new FriendlyLink()
                {  
                    Url = "http://www.baidu.com",
                    Top = true,
                    Name = "百度",
                    DisplayOrder = 1,
                    Active =true,
                },
                new FriendlyLink()
                {  
                    Url = "http://www.sina.com.cn",
                    Top = true,
                    Name = "新浪",
                    DisplayOrder = 2,
                    Active =true,
                },
                new FriendlyLink()
                {  
                    Url = "http://www.163.com",
                    Top = true,
                    Name = "网易",
                    DisplayOrder = 3,
                    Active =true,
                },
                new FriendlyLink()
                {  
                    Url = "http://www.ifeng.com",
                    Top = true,
                    Name = "凤凰网",
                    DisplayOrder = 4,
                    Active =true,
                },
            };

            links.ForEach(x => _friendlyLinkRepository.Insert(x));
        }

        /// <summary>
        /// 安装规模
        /// </summary>
        protected virtual void InstallScales()
        {
            var scales = new List<Scale>()
            {
                new Scale()
                {  
                    Name = "50人以下",
                    DisplayOrder = 1,
                    Active =true,
                },
                new Scale()
                {  
                    Name = "50-100人",
                    DisplayOrder = 1,
                    Active =true,
                },
                new Scale()
                {  
                    Name = "100-200人",
                    DisplayOrder = 3,
                    Active =true,
                },
                new Scale()
                {  
                    Name = "200-500人",
                    DisplayOrder = 4,
                    Active =true,
                }, 
                new Scale()
                {  
                    Name = "500-2000人",
                    DisplayOrder = 5,
                    Active =true,
                },
                new Scale()
                {  
                    Name = "2000人以上",
                    DisplayOrder = 6,
                    Active =true,
                },
            };

            scales.ForEach(x => _scaleRepository.Insert(x));
        }

        /// <summary>
        /// 增加公司
        /// </summary>
        protected virtual void InstallCompanys()
        {
            var companys = new List<Company>()
            {
                new Company()
                {  
                    Name = "百度",
                    DisplayOrder = 1,
                    Active =true,
                    CityId = 1,
                    Memo = "百度一下，你就知道",
                    URL="http://www.baidu.com",
                    CreateOn = DateTime.Now,
                    Deleted = false,
                    ScaleId = 0,
                    CustomerId = _customerRepository.Table.FirstOrDefault(u=>u.Username =="bbb@admin.com").Id,
                },
                new Company()
                {  
                    Name = "新浪",
                    DisplayOrder = 1,
                    Active =true,
                    CustomerId = _customerRepository.Table.FirstOrDefault(u=>u.Username =="bbb@admin.com").Id,                    
                    CityId = 1,
                    Memo = "新浪一下你就忘了",
                    URL="http://www.sina.com.cn",
                    CreateOn = DateTime.Now,
                    Deleted = false,
                    ScaleId = 0,
                },
            };

            companys.ForEach(x => _companyRepository.Insert(x));

            var jobs = new List<Jobs>
            {
                new Jobs(){
                Active =true,
                CategoryId = _categoryRepository.Table.Single(s=>s.Name== "技术").Id,
                CompanyId = _companyRepository.Table.Single(s=>s.Name =="新浪").Id,
                CreatedOn =DateTime.Now,
                Deleted =false,
                JobWorkType = WorkType.FullTime,
                Memo="闲着",
                Name = "闲着攻城师",
                Times =1,
                WrokTypeId = (int)WorkType.FullTime,                
                },
                
                new Jobs(){
                Active =true,
                CategoryId = _categoryRepository.Table.Single(s=>s.Name== "销售").Id,
                CompanyId = _companyRepository.Table.Single(s=>s.Name =="百度").Id,
                CreatedOn =DateTime.Now,
                Deleted =false,
                JobWorkType = WorkType.FullTime,
                Memo="闲着",
                Name = "闲着攻城师",
                Times =1,
                WrokTypeId = (int)WorkType.FullTime,                
                },
            };
            jobs.ForEach(x => _jobRepository.Insert(x));
        }

        /// <summary>
        /// 本地化服务
        /// </summary>
        protected virtual void InstallLocalStringRepository()
        {
            var locals = new List<LocaleStringResource>
            {
                new LocaleStringResource()
                {
                ResourceName="enums.core.domain.companys.companysortingenum.createup",
                ResourceValue="时间正序",
                },
                new LocaleStringResource()
                {
                ResourceName="enums.core.domain.companys.companysortingenum.createdown",
                ResourceValue="时间倒序",
                },

                new LocaleStringResource()
                {
                ResourceName="Enums.Core.Domain.Customers.ResumeSortingEnum.DisplayOrderUp",
                ResourceValue="权重正序",
                },
                new LocaleStringResource()
                {
                ResourceName="Enums.Core.Domain.Customers.ResumeSortingEnum.DisplayOrderDown",
                ResourceValue="权重倒序",
                },
                new LocaleStringResource()
                {
                ResourceName="Enums.Core.Domain.Customers.ResumeSortingEnum.CreateUp",
                ResourceValue="创时间正序",
                },
                new LocaleStringResource()
                {
                ResourceName="enums.core.domain.customers.resumesortingenum.createdown",
                ResourceValue="创建时间倒序",
                },
                new LocaleStringResource()
                {
                ResourceName="enums.core.domain.customers.resumesortingenum.timesup",
                ResourceValue="浏览量正序",
                },
                new LocaleStringResource()
                {
                ResourceName="enums.core.domain.customers.resumesortingenum.timesdown",
                ResourceValue="浏览量倒序",
                },
                new LocaleStringResource()
                {
                ResourceName="enums.core.domain.common.worktype.fulltime",
                ResourceValue="全职",                    
                },
                new LocaleStringResource()
                {
                ResourceName="enums.core.domain.common.worktype.parttime",
                ResourceValue="兼职",                    
                },
                new LocaleStringResource()
                {
                ResourceName="enums.core.domain.common.worktype.other",
                ResourceValue="其他",                    
                },
            };

            locals.ForEach(x => _localStringRepository.Insert(x));
        }

        /// <summary>
        /// 安装地域
        /// </summary>
        protected virtual void InstallDirectory()
        {
            var states = new List<StateProvince> { 
                new StateProvince(){Name="北京市",DisplayOrder=1},
                new StateProvince(){Name="上海市",DisplayOrder=2},
                new StateProvince(){Name="广东省",DisplayOrder=3},
            };

            states.ForEach(x => _stateRepository.Insert(x));

            var s = _stateRepository.Table.FirstOrDefault(x => x.Name == "北京市");
            var citys = new List<City>{
                new City (){StateId = 1,Name="北京市",IsHot=true,DisplayOrder=1},
                new City (){StateId = 2,Name="上海市",IsHot=true,DisplayOrder=1},
                new City (){StateId = 3,Name="深圳市",IsHot=true,DisplayOrder=1},
                new City (){StateId = 3,Name="广州市",IsHot=true,DisplayOrder=2},
            };

            citys.ForEach(x => _cityRepository.Insert(x));
        }


        /// <summary>
        /// 安装属性数据
        /// </summary>
        protected virtual void InstallExtend()
        {
            var extends = new List<ExtendedAttribute> { 
                new ExtendedAttribute(){Memo="",DisplayOrder=1,Name="行业领域",ExtendEnumId = (int)ExtendEnum.Company},
                new ExtendedAttribute(){Memo="",DisplayOrder=1,Name="公司规模",ExtendEnumId = (int)ExtendEnum.Company},
                new ExtendedAttribute(){Memo="",DisplayOrder=1,Name="薪金要求",ExtendEnumId = (int)ExtendEnum.Jobs},
            };
            extends.ForEach(x => _extendRepository.Insert(x));

            var extendValues = new List<ExtendedAttributeValue> { 
            new ExtendedAttributeValue(){Value="移动互联",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="行业领域").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="行业领域"),DisplayOrder=1},
            new ExtendedAttributeValue(){Value="电子商务",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="行业领域").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="行业领域"),DisplayOrder=2},
            new ExtendedAttributeValue(){Value="O2O",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="行业领域").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="行业领域"),DisplayOrder=3},
            new ExtendedAttributeValue(){Value="游戏",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="行业领域").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="行业领域"),DisplayOrder=4},
            new ExtendedAttributeValue(){Value="硬件",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="行业领域").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="行业领域"),DisplayOrder=5},

            new ExtendedAttributeValue(){Value="20人以下",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="公司规模").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="公司规模"),DisplayOrder=1},
            new ExtendedAttributeValue(){Value="20-100人",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="公司规模").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="公司规模"),DisplayOrder=2},
            new ExtendedAttributeValue(){Value="100-500人",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="公司规模").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="公司规模"),DisplayOrder=3},
            new ExtendedAttributeValue(){Value="500人以上",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="公司规模").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="公司规模"),DisplayOrder=4},

            new ExtendedAttributeValue(){Value="5k以下",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="薪金要求").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="薪金要求"),DisplayOrder=1},
            new ExtendedAttributeValue(){Value="5-10k",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="薪金要求").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="薪金要求"),DisplayOrder=2},
            new ExtendedAttributeValue(){Value="10-15k",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="薪金要求").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="薪金要求"),DisplayOrder=3},
            new ExtendedAttributeValue(){Value="15-25k",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="薪金要求").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="薪金要求"),DisplayOrder=4},
            new ExtendedAttributeValue(){Value="25k以上",ExtendedAttributeId = _extendRepository.Table.Single(x=>x.Name=="薪金要求").Id,ExtendedAttribute= _extendRepository.Table.Single(x=>x.Name=="薪金要求"),DisplayOrder=5},
            };

            extendValues.ForEach(x => _extendValueRepository.Insert(x));
        }

        /// <summary>
        /// 插入简历
        /// </summary>
        protected virtual void InstallResumes()
        {
            var resumes = new List<Resume> { 
                new Resume(){
                    Active=true,
                    CityId=1,
                    CreateOn=DateTime.Now,
                    Customer=_customerRepository.Table.SingleOrDefault(x=>x.Username =="aaa@admin.com"),
                    CustomerId=_customerRepository.Table.SingleOrDefault(x=>x.Username =="aaa@admin.com").Id,
                    Deleted=false,
                    DisplayOrder=999,
                    Email="aaa@admin.com",
                    Evaluation="",
                    Name="张三",
                    Phone="13800000000",
                    ReadTimes=17,
                    ResumeName="张三的简历",
                    SexId = (int)Sex.Man,
                    UpdateOn=DateTime.Now,
                    WorkCityId =1,
                    WorkStateId = (int)WorkState.Change,
                    WorkTypeId = (int)WorkType.FullTime,
                    WorkYear=8,                    
                },
            };
            resumes.ForEach(x => _resumeRepository.Insert(x));

            var works = new List<WorkExperience> { 
                new WorkExperience(){
                    Company="某某某公司",
                    EndWorkMonth=10,
                    EndWorkYear=2010,
                    IsHideCorp=true,
                    JobName="软工",
                    Resume=_resumeRepository.Table.SingleOrDefault(x=>x.Name=="张三"),
                    ResumeId=_resumeRepository.Table.SingleOrDefault(x=>x.Name=="张三").Id,
                    Salary="保密",
                    StartWorkMonth=12,
                    StartWorkYear=2005,
                    WorkMemo="",                    
                },
                new WorkExperience(){
                    Company="第二个",
                    EndWorkMonth=10,
                    EndWorkYear=2014,
                    IsHideCorp=true,
                    JobName="软工",
                    Resume=_resumeRepository.Table.SingleOrDefault(x=>x.Name=="张三"),
                    ResumeId=_resumeRepository.Table.SingleOrDefault(x=>x.Name=="张三").Id,
                    Salary="保密",
                    StartWorkMonth=12,
                    StartWorkYear=2010,
                    WorkMemo="",                    
                },
            };
            works.ForEach(x => _workRepository.Insert(x));

            var educations = new List<Education> { 
                new Education(){
                    DegreeID = 1,
                    EndMonth=9,
                    EndYear=2006,
                    Name="石家庄铁道大学",
                    Resume=_resumeRepository.Table.SingleOrDefault(x=>x.Name=="张三"),
                    ResumeId=_resumeRepository.Table.SingleOrDefault(x=>x.Name=="张三").Id,
                    Specialty="计算机",
                    StartMonth=9,
                    StartYear=2002,
                },
            };
            educations.ForEach(x => _educationRepository.Insert(x));
        }

        #endregion

        #region Methods

        /// <summary>
        /// 增加数据
        /// </summary>
        /// <param name="defaultUserEmail"></param>
        /// <param name="defaultUserPassword"></param>
        /// <param name="installSampleData"></param>
        public virtual void InstallData(string defaultUserEmail,
            string defaultUserPassword, bool installSampleData = true)
        {
            InstallStores();
            InstallExtend();
            InstallCustomersAndUsers(defaultUserEmail, defaultUserPassword);
            InstallSettings();
            InstallLocalStringRepository();
            InstallTopics();
            InstallCategories();
            InstallFriendlyLinks();
            InstallScales();
            InstallCompanys();
            InstallDirectory();
            InstallResumes();
        }

        #endregion
    }
}